#include "EquipmentIntoNetCmd.h"

EquipmentIntoNetCmd::EquipmentIntoNetCmd(QObject *parent) :
    BaseCmd(parent)
{
    this->m_protocolType = ProtocolType::ZigbeeControlProtocol;
    this->m_functionCode = FunctionCode;
}

Package EquipmentIntoNetCmd::toPackage()
{
    Package package;
    return package;
}

void EquipmentIntoNetCmd::unPackage(Package package)
{
    QByteArray body = package.body();
    quint16 index = 0;

    QByteArray mac = body.mid(index,8);
    index += 8;

    QByteArray nwk = body.mid(index,2);
    index += 2;

    m_index = body.mid(index,1).toHex().toUInt(0,16);
    index += 1;

    quint8 size = body.mid(index,1).toHex().toUInt(0,16);
    index += 1;

    QList<ControlPointStruct> pointList;
    for(int i=0; i<size; i++)
    {
        quint16 address = (quint16)body.at(index+1) <<8 | (quint8)body.at(index);
        index += 2;

        ControlPointStruct point;
        point.setAddress(address);

        pointList.append(point);
    }

    m_zigbee.setMac(mac);
    m_zigbee.setNwk(nwk);
    m_zigbee.setPointList(pointList);

}
quint8 EquipmentIntoNetCmd::index() const
{
    return m_index;
}

void EquipmentIntoNetCmd::setIndex(const quint8 &index)
{
    m_index = index;
}
ZigbeeStruct EquipmentIntoNetCmd::zigbee() const
{
    return m_zigbee;
}

void EquipmentIntoNetCmd::setZigbee(const ZigbeeStruct &zigbee)
{
    m_zigbee = zigbee;
}



